package com.joymart.admin.rest;


import com.joymart.common.utils.SecurityUtils;
import com.joymart.user.service.UserCacheManager;
import com.joymart.user.service.UserRestAuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/users/partyA")
public class PartyAUserAdminController {

    @Autowired
    private UserRestAuthorityService userRestAuthorityService;
    @Autowired
    private UserCacheManager userCacheManager;

    @PutMapping("/{id}/restAuthorities")
    public void changeRestAuthorities(@PathVariable("id") String userId, @RequestBody List<String> authorities) {
        SecurityUtils.requiresRestAuthority("PartyAUserManagement");
        userRestAuthorityService.deleteByUserId(userId);
        userRestAuthorityService.insert(userId, authorities);
        userCacheManager.invalidateUser(userId);
    }


}
